package com.aggregate.pay.sanstar.support.client;

import com.aggregate.pay.sanstar.Result;
import com.aggregate.pay.sanstar.Result.Status;
import com.aggregate.pay.sanstar.bean.AttachLoadData;
import com.aggregate.pay.sanstar.bean.AttachLoadResult;
import com.aggregate.pay.sanstar.support.AbstractClient;
import com.aggregate.pay.sanstar.support.Factory;
import com.aggregate.pay.sanstar.support.HttpClient;
import com.aggregate.pay.sanstar.support.Merch;


/**
 * 附件下载
 * @author Moyq5
 * @date 2024年4月19日
 * @param <T>
 */
public class AttachLoad<T> extends AbstractClient<AttachLoadData, AttachLoadResult<T>> {

	private Class<T> clazz;
	
	public AttachLoad(Merch merch, Class<T> clazz) {
	    super(merch);
		this.clazz = clazz;
	}
	
	@Override
	public Result<AttachLoadResult<T>> doExecute(AttachLoadData data) throws Exception {
		Result<AttachLoadResult<T>> resResult = new Result<>();
		HttpClient client = Factory.getHttpClient();
        T response = client.post(getServerPath(), getReqBody(data), clazz);
        AttachLoadResult<T> result = new AttachLoadResult<>();
        result.setResponse(response);
        resResult.setData(result);
        resResult.setStatus(Status.OK);
        resResult.setMessage("下载成功");
		return resResult;
	}

    @Override
    protected Class<? extends AttachLoadResult<T>> getResultClass() {
        return null;
    }

    @Override
    protected String getServerPath() {
        return Factory.getConfig().getServerPath() + "/attach/load";
    }
	
}
